home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-apt / examples / versiontest.py < prev   
Encoding:
Python Source  |  2009-03-30  |  1.1 KB  |  40 lines

  1. #!/usr/bin/python
  2.  
  3. # This is a simple clone of tests/versiontest.cc
  4. import apt_pkg
  5. import sys
  6. import re
  7.  
  8. apt_pkg.InitConfig()
  9. apt_pkg.InitSystem()
  10.  
  11. TestFile = apt_pkg.ParseCommandLine(apt_pkg.Config, [], sys.argv)
  12. if len(TestFile) != 1:
  13.     print "Must have exactly 1 file name"
  14.     sys.exit(0)
  15.  
  16. # Go over the file..
  17. List = open(TestFile[0], "r")
  18. CurLine = 0
  19. while(1):
  20.     Line = List.readline()
  21.     CurLine = CurLine + 1
  22.     if Line == "":
  23.         break
  24.     Line = Line.strip()
  25.     if len(Line) == 0 or Line[0] == '#':
  26.         continue
  27.  
  28.     Split = re.split("[ \n]", Line)
  29.  
  30.     # Check forward
  31.     if apt_pkg.VersionCompare(Split[0], Split[1]) != int(Split[2]):
  32.         print "Comparision failed on line %u. '%s' ? '%s' %i != %i" % (CurLine,
  33.             Split[0], Split[1], apt_pkg.VersionCompare(Split[0], Split[1]),
  34.             int(Split[2]))
  35.     # Check reverse
  36.     if apt_pkg.VersionCompare(Split[1], Split[0]) != -1 * int(Split[2]):
  37.         print "Comparision failed on line %u. '%s' ? '%s' %i != %i" % (CurLine,
  38.             Split[1], Split[0], apt_pkg.VersionCompare(Split[1], Split[0]),
  39.             -1 * int(Split[2]))
  40.